package com.application.fabric.fabriccontrol.operate.serverfabric;

import com.application.fabric.fabriccontrol.operate.entityfabric.BasicAsset;
import com.application.fabric.users.config.Dealmsg;
import com.application.fabric.users.config.HDFS.HadoopTemplate;
import com.application.fabric.users.entity.Evidence;
import com.application.fabric.users.entity.ExtractToken;
import com.application.fabric.users.entity.Returnmsg;
import com.application.fabric.users.service.Exsiting;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class HDFSservice {
//    作文件存储

    //    创建用户目录
    @Resource
    public ExtractToken token;
    @Autowired
    private Dealmsg dealmsg;
    @Resource
    private Returnmsg returnmsg;
    @Autowired
    private HadoopTemplate hadoopTemplate;
    @Autowired
    private Exsiting exsiting;
    public int issueservice(BasicAsset basicAsset,String name) throws Exception {
//       hdfs用户目录创建
        String hdfsuserpath = "/user/"+token.getUserid();
//        文件存储路径
        String hdfspath = hdfsuserpath+"/"+name;
        /*判断目录是否存在 不存在则进行创建*/
        hadoopTemplate.existDir(hdfsuserpath,true);
//        进行文件写入
        hadoopTemplate.writer(hdfspath,basicAsset.getFile().getInputStream());
        return  1;
    }
}
